package org.osflash.signals;

import asunit.asserts.*;
import asunit.framework.IAsync;
import org.osflash.signals.events.GenericEvent;

class RedispatchedEventTest {

	@:meta(Inject())
	public var async : IAsync;
	public var completed : DeluxeSignal;
	var originalEvent : GenericEvent;
	@:meta(Before())
	public function setUp() : Void {
		completed = new DeluxeSignal(this);
	}

	@:meta(After())
	public function tearDown() : Void {
		completed.removeAll();
		completed = null;
	}

	//////
	@:meta(Test())
	public function dispatch_event_already_dispatched_should_clone_it() : Void {
		completed.add(async.add(redispatchEvent, 10));
		originalEvent = new GenericEvent();
		completed.dispatch(originalEvent);
	}

	function redispatchEvent(e : GenericEvent) : Void {
		cast((e.signal), DeluxeSignal).removeAll();
		assertSame(originalEvent, e);
		completed.add(async.add(check_redispatched_event_is_not_original, 10));
		completed.dispatch(originalEvent);
	}

	function check_redispatched_event_is_not_original(e : GenericEvent) : Void {
		assertNotSame(originalEvent, e);
	}

}

